package com.example.springboot.mapper;
import org.apache.ibatis.annotations.*;
import java.util.List;
import com.example.springboot.pojo.Cart;
@Mapper
public interface CartMapper {
    @Insert("insert into cart(goods_id,user_id,goods_number) " +
            "values(#{goodsId},#{userid},#{goodsnumber})")
    void create(Cart cart) ;
    @Delete("delete from cart where id=#{id}")
    void delete(Integer id) ;
    @Select({"SELECT  c.id, c.goods_number,c.user_id,c.goods_id ,g.photo AS goodsPhoto , g.name AS goodsName, g.price AS goodsPrice,u.user_address AS userAddress",
            "FROM cart c",
            "LEFT JOIN goods g ON c.goods_id = g.id",
            "LEFT JOIN user u ON c.user_id = u.id",
            "WHERE c.user_id=#{userid}"})
    List<Cart> findByUserId(Integer userid) ;
    @Update("update cart set goods_number=#{goodsnumber} where id=#{id}")
    void updateById(Cart cart);

    @Select({"select * from cart where user_id=#{userid} and goods_id=#{goodsId}"})
    Cart selectByUserIdAndGoodsId(Integer userid, Integer goodsId);

}
